<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=no">
    <meta http-equiv="X-UA-Compatible" content="ie=edge,chrome=1">
    <meta name="referrer" content="never">
    <title>作业</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }
        ul {
            list-style: none;
        }
    </style>
</head>
<body>
    
    <script type="text/javascript">
        // sum(a)(b) => a + b
        function sum(a){
            return function (b){
                console.log(a + b);
            }
        }

        // var sum1 = sum(1);
        sum(4)(5);

        // 简化sort排序，接受 byField(筛选条件)
        var users = [
            { name: "John", age: 20 },
            { name: "Pete", age: 18 },
            { name: "Ann", age: 19 },
        ]
        users.sort( byField("name") );
        console.log(users);

        users.sort( byField("age") );
        console.log(users);

        function byField(key){
            return function (a, b){
                return a[key] > b[key] ? 1 : -1;
            }
        }
    </script>
</body>
</html>